package com.sailfish.springbootdemo.utils;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;

public class ExcelStyleUtil {
    public static XSSFCellStyle setBorderAndFont(Workbook workbook, BorderStyle borderStyle, boolean isBold, short color, short bg ){
        XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle();
        style.setBorderBottom(borderStyle);
        style.setBorderLeft(borderStyle);
        style.setBorderRight(borderStyle);
        style.setBorderTop(borderStyle);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setAlignment(HorizontalAlignment.LEFT);
        //创建字体 加粗
        XSSFFont font = (XSSFFont) workbook.createFont();
        font.setBold(isBold);
        font.setFontHeight(11);

        font.setColor(color);
        style.setFont(font);
        style.setFillForegroundColor(bg);
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return style;
    }
}
